const config = require('./config');
const utils = require('./utils');
const baseConfig = require('./webpack.base.conf');
const webpack = require('webpack');
const { merge } = require('webpack-merge');
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');

// 将热加载相关代码添加输入块中
Object.keys(baseConfig.entry).forEach(function (name) {
  baseConfig.entry[name] = ['webpack-hot-client5/client'].concat(baseConfig.entry[name]);
});

module.exports = merge(baseConfig, {
  mode: 'development',
  module: {
    rules: utils.styleLoaders({
      sourceMap: config.dev.cssSourceMap,
      usePostCSS: true
    })
  },

  // 开发模式下使用cheap-module-eval-source-map模块便于快速定位
  devtool: config.dev.devtool,
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new FriendlyErrorsPlugin()
  ]
});
